package cn.bdqn.pn.service.user.impl;

import cn.bdqn.pn.pojo.user.Role;
import cn.bdqn.pn.reposity.user.RoleReposity;
import cn.bdqn.pn.service.user.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleReposity roleReposity;
    @Override
    /**
     * 查询角色信息
     */
    public Page<Role> selectRole(Integer pageNo, Integer pageSize) {
        Pageable pageable=new PageRequest(pageNo,pageSize);

        Page<Role> page = roleReposity.findAll(pageable);
        return page;
    }

    @Override
    public Role findRoleById(Integer roleId) {
        return roleReposity.findOne(roleId);
    }

    @Override
    public List<Role> selectAllRole() {
        return roleReposity.findAll();
    }

    @Override
    public List<Role> findRoleId(Integer roleId) {
        return roleReposity.findByRoleId(roleId);
    }


    @Override
    /**
     * 新增角色
     */
    public void addRole(Role role) {
        roleReposity.save(role);
    }

    @Override
    public void updateRole(Role role) {
        roleReposity.save(role);
    }

    @Override
    public void deleteRole(Integer roleId) {
        roleReposity.delete(roleId);
    }
}

